package com.ln.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.ln.Util.JwtUtil;
import com.ln.dao.User02Dao;
import com.ln.entity.User02;
import com.ln.service.User02Service;
import com.ln.vo.LoginVo;
import com.ln.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;

/**
 * @author Ln
 * @version 终极版
 * @date 2022/11/23 15:57
 */
@Service
public class User02ServiceImpl implements User02Service {
    @Autowired
    private User02Dao user02Dao;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result select(LoginVo loginVo) {
        QueryWrapper<User02> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("nikename",loginVo.getNikename());
        objectQueryWrapper.eq("password",loginVo.getPassword());
        User02 user02 = user02Dao.selectOne(objectQueryWrapper);
        HashMap<String, Object> map = new HashMap<>();
        if (user02!=null){
            map.put("nikename",loginVo.getNikename());
            map.put("password",loginVo.getPassword());
            String token = JwtUtil.createToken(map);
            return new Result(2000,"登陆成功",token);
        }else {
            return new Result(5000,"登录失败",null);
        }

    }
}
